package com.cn.zy.ehcache.service.impl;

import com.cn.zy.ehcache.model.User;
import com.cn.zy.ehcache.service.UserService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangyi
 * @date 2018/12/13 14:38
 */
@Service
@CacheConfig(cacheNames = "users")
public class UserServiceImpl implements UserService{

    @Cacheable(value = "users")
    @Override
    public List<User> getAllUser(){
        List<User> list = new ArrayList<>();
        for(int i = 0; i < 5; i++) {
            User user = new User();
            user.setUserName(String.valueOf(i+Math.random()*10));
            user.setPassWord(String.valueOf(i));
            list.add(user);
        }
        System.out.println("模拟数据库查询... 过程");
        return list;
    }
}
